$(function () {
    $JuXue.calenders("#cExTime",false,true);
    /**初始化部门**/
    $.post(ctx+"dept/list",{},function (r) {
        $("#cExDept").empty().append("<option value=''>请选择分配部门</option>");
        $.each(r,function (index,val) {
            $("#cExDept").append("<option value='"+val.deptId+"'>"+val.deptName+"</option>");
        });
    });
});
/**选择分配方式**/
function exfenMethos() {
    var cExMethod = $("#cExMethod").val();
    if (cExMethod == "1"){
        $("#cExMethod").parent().removeClass("col-md-2").addClass("col-md-10");
        $("#cExtNone").addClass("b-none");
    }else{
        $("#cExMethod").parent().removeClass("col-md-10").addClass("col-md-2");
        $("#cExtNone").removeClass("b-none");
    }
}
/**切换部门**/
function changeDept(){
    var deptid = $("#cExDept").val();
    if (deptid !=""){
        $.post(ctx+"user/selectUserByDept",{deptId:deptid},function (r) {
            $("#cExReceiver").empty().append("<option value=''>请选择分配人员</option>");
            $.each(r,function (index,val) {
                $("#cExReceiver").append("<option value='"+val.userUuid+"'>"+val.nickname+"</option>");
            });
        });
    }else{
        $("#cExReceiver").empty().append("<option value=''>请选择分配人员</option>");
    }
}
/**保存数据**/
function saveExEmpInfo(btn) {
    $(btn).attr("disabled","disabled");
    //验证意向项目
    var inter  = $("#cExIntern").val();
    if (inter == ""){$JuXue.n_warning("请选择意向项目");$(btn).removeAttrs("disabled");return;}
    var form_data = $("#add_exEmp_form").serialize();
    var strContent = document.getElementById("cExRemarks").value;
    strContent = strContent.replace(/\r\n/g, '<br/>'); //IE9、FF、chrome
    strContent = strContent.replace(/\n/g, '<br/>'); //IE7-8
    strContent = strContent.replace(/\s/g, ' '); //空格处理
    var data = form_data+"&cExRemarks="+strContent;

    $.post(ctx+"seaExtension/saveExEmp",data,function (r) {
        if (r.code == 0){
            $JuXue.n_success("新增成功");//
            var msg = r.msg;
            if (msg >=0) {$JuXue.n_warning("当前轮询部门可分配余额还有:"+msg+" 个。请及时更改配置");}
            $("#myCustomer-modal").empty().modal('hide');
            $JuXue.refreshTable("bigExEmpTable");
        }else{
            $JuXue.n_danger(r.msg);
            $(btn).removeAttrs("disabled");
        }
    });
}
/**保存渠道**/
function seeck(btn) {
    var text = $(btn).text();
    $("#cExChanel").val(text);
}
/**保存地区**/
function seeckzone(btn) {
    var text = $(btn).text();
    $("#cExzone").val(text);
}

/**初始化验证信息**/
function validateRule() {
    var icon = "<i class='zmdi zmdi-close-circle zmdi-hc-fw'></i> ";
    validator = $("#add_bigEmp_form").validate({
        rules: {
            bpName: {
                required: true,
                maxlength: 10
            },
            bpMobile: {
                required: true,
                remote: {
                    url: ctx+"bigEpResoure/checkUserMobile",
                    type: "get",
                    dataType: "json",
                    data: {
                        bpMobile: function (){
                            return $("#bpMobile").val().trim();
                        }
                    }
                }
            }
        },
        messages: {
            bpMobile: {
                required: icon + "请输入手机号",
                remote: icon + "手机号已经存在或者输入有误"
            },
            bpName: {
                required: icon + "请输入客户名",
                minlength: icon + "用户名长度3到10个字符"
            }
        }
    });
}